<?php
class QSource_System_Route_Route { 
        public function GetInitRoute(){
        	
        	$modelArticle = new QSource_System_Models_Article();
        	$modelArticleCat = new QSource_System_Models_ArticleCat();
        	$modelProduct = new QSource_System_Models_Product();
        	$modelProductCat = new QSource_System_Models_ProductCat();
        	$modelTag = new QSource_System_Models_Tag();
        	$router = new Zend_Controller_Router_Rewrite();
        	$str = new QSource_System_Helper_String();
        	foreach ($modelArticle->getAllItemsActive() as $item)
        	{
        		if($item['category']!=1)
        		{
        			$articatAlias = $modelArticleCat->getAliasById($item['category']);
        			$router->addRoute('article-detail-'.$item['alias'],
					new Zend_Controller_Router_Route_Regex(
			 		$articatAlias.'/'.$item['alias'].'\.html', 
			 		array('module'=>'default','controller'=>'article','action'=>'detail','alias'=>$item['alias']))
					);
        		}
        		else
        		{
        			$articatAlias = $modelArticleCat->getAliasById($item['category']);
        			$router->addRoute('article-detail-'.$item['alias'],
					new Zend_Controller_Router_Route_Regex(
			 		$item['alias'].'\.html', 
			 		array('module'=>'default','controller'=>'article','action'=>'detail','alias'=>$item['alias']))
					);
        		}
        	}
        	
      	 	foreach ($modelArticleCat->getAllRootCatActive() as $item)
        	{
        		$router->addRoute('articleCat-detail-root-'.$item['alias'],
				 new Zend_Controller_Router_Route_Regex(
			 		$item['alias'].'\.html', 
			 	array('module'=>'default','controller'=>'articlecat','action'=>'detail','alias'=>$item['alias']))
			 );
        		$router->addRoute('articleCat-detail-root-'.$item['alias'].'-page',
        				new Zend_Controller_Router_Route_Regex(
        						$item['alias'].'-trang-(.*)\.html',
        						array('module'=>'default','controller'=>'articlecat','action'=>'detail','alias'=>$item['alias']),array('1'=>'page'))
        		);
			 
        	}
       	 	foreach ($modelArticleCat->getAllLeapCatActive() as $item)
        	{
        		if($item['id']!=1)	
        		{
	        		$parentAlias = $modelArticleCat->getAliasById($item['parent_id']);
	        		$router->addRoute('articleCat-detail-leap-'.$item['alias'],
					 new Zend_Controller_Router_Route_Regex(
				 		$parentAlias.'/'.$item['alias'].'\.html', 
				 	array('module'=>'default','controller'=>'articlecat','action'=>'detail','alias'=>$item['alias']))
				 	);
	        		$router->addRoute('articleCat-detail-leap-'.$item['alias'].'-page',
	        				new Zend_Controller_Router_Route_Regex(
	        						$parentAlias.'/'.$item['alias'].'-trang-(.*)\.html',
	        						array('module'=>'default','controller'=>'articlecat','action'=>'detail','alias'=>$item['alias']),array('1'=>'page'))
	        		);
        	}
        	
			 
        	}
        	$router->addRoute('Site-under-contruction',
        			new Zend_Controller_Router_Route_Regex(
        					'dang-xay-dung\.html',
        					array('module'=>'default','controller'=>'index','action'=>'undercontruction'))
        	);
        	$router->addRoute('Product-Page',
        			new Zend_Controller_Router_Route_Regex(
        					'san-pham\.html',
        					array('module'=>'default','controller'=>'product','action'=>'index'))
        	);
        	foreach ($modelProduct->getAllIsActive() as $item)
        	{
        			$productCatAlias = $modelProductCat->getAliasById($item['category']);
        			$router->addRoute('Products-detail-'.$item['alias'],
					new Zend_Controller_Router_Route_Regex(
			 		$productCatAlias.'/'.$item['alias'].'\.html', 
			 		array('module'=>'default','controller'=>'product','action'=>'detail','alias'=>$item['alias']))
					);
        	}
        	foreach ($modelProductCat->getAll() as $item)
        	{
        		$router->addRoute('ProductCats-detail-root-'.$item['alias'],
				 new Zend_Controller_Router_Route_Regex(
			 		$item['alias'].'\.html', 
			 	array('module'=>'default','controller'=>'product','action'=>'category','alias'=>$item['alias']))
			 );			 
        	}
        	$router->addRoute('Site-under-contruction',
        			new Zend_Controller_Router_Route_Regex(
        					'offline\.html',
        					array('module'=>'default','controller'=>'index','action'=>'siteoffline'))
        	);
        	$router->addRoute('Contact-Page',
        			new Zend_Controller_Router_Route_Regex(
        					'lien-he\.html',
        					array('module'=>'default','controller'=>'index','action'=>'contact'))
        	);
        	$router->addRoute('Search-Page',
        			new Zend_Controller_Router_Route_Regex(
        					'tim-kiem\.html',
        					array('module'=>'default','controller'=>'article','action'=>'search'))
        	);
        	$router->addRoute('Place-Page',
        			new Zend_Controller_Router_Route_Regex(
        					'he-thong-cua-hang\.html',
        					array('module'=>'default','controller'=>'index','action'=>'place'))
        	);
        	/* $router->addRoute('category-Detail-Page',
				 new Zend_Controller_Router_Route_Regex(
				 'the-loai/(.*)-(.*)\.html', 
				 array('module'=>'default','controller'=>'articlecat','action'=>'detail'), 
				 array('1'=>'alias','2'=>'page'))
				 ); */
        	
        	//Route About
        	/* 
        	$router->addRoute('abut',
				 new Zend_Controller_Router_Route_Regex(
			 		'gioi-thieu\.html', 
			 	array('module'=>'default','controller'=>'index','action'=>'about'))
			 );
        	 */
        	
        	return $router;
        }
	
}